package org.apache.servicecomb.samples.practise.houserush.realestate.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Entity
@Table(name = "realestates")
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update realestates set deleted_at = now() where id = ?")
@Where(clause = "deleted_at is null")
public class Realestate {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String name;
    private String description;
    @Temporal(TemporalType.TIMESTAMP)
    private Date deletedAt;
    @Temporal(TemporalType.TIMESTAMP)
    @CreatedDate
    private Date createdAt;
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedAt;
    private String address;
    private String type;
    private String avgprice;
    private String useyear;
    private String usernum;
    private String area;
    private String buildname;


    @JsonIgnoreProperties(ignoreUnknown = true, value = {"realestate"})
    @OneToMany(mappedBy = "realestate") //配置一对多
    private List<Building> buildings = new ArrayList<>();
}
